package com.envocabulary.widget_list;

import java.util.Calendar;

import android.app.Activity;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.Toast;

import com.envocabulary.Ultis.Reference;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;

public class SettingsActivity extends Activity {

	private String[] time = { "30 phút", "1 tiếng", "6 tiếng", "12 tiếng",
			"1 ngày" };

	Spinner spinnerTime;

	private String[] type = { "Từ vựng", "Câu thông dụng", "Động từ" };

	Spinner spinnerType;

	Button mButtonSave;
	
	private PendingIntent service = null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.setting);

		Reference.loadSaveData(getApplicationContext());
		mButtonSave = (Button) findViewById(R.id.btn_save_setting);
		setTitle(getResources().getString(R.string.setting));

		spinnerTime = (Spinner) findViewById(R.id.setting_refresh_spinner);
		ArrayAdapter<String> adapter_time = new ArrayAdapter<String>(this,
				android.R.layout.simple_spinner_item, time);
		adapter_time
				.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		spinnerTime.setAdapter(adapter_time);

		spinnerType = (Spinner) findViewById(R.id.setting_type_spinner);

		ArrayAdapter<String> adapter_type = new ArrayAdapter<String>(this,
				android.R.layout.simple_spinner_item, type);
		adapter_type
				.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		spinnerType.setAdapter(adapter_type);

		spinnerTime.setOnItemSelectedListener(new OnItemSelectedListener() {

			public void onItemSelected(AdapterView<?> parent, View view,
					int position, long id) {
				spinnerTime.setSelection(position);
				if(position == 0)
					Reference.TYPE_TIME = 30;
				if(position == 1)
					Reference.TYPE_TIME = 60;
				if(position == 2)
					Reference.TYPE_TIME = 360;
				if(position == 3)
					Reference.TYPE_TIME = 720;
				if(position == 4)
					Reference.TYPE_TIME = 1440;
			}

			@Override
			public void onNothingSelected(AdapterView<?> arg0) {
				// TODO Auto-generated method stub

			}

		});

		spinnerType.setOnItemSelectedListener(new OnItemSelectedListener() {

			public void onItemSelected(AdapterView<?> parent, View view,
					int position, long id) {
				spinnerType.setSelection(position);
				Reference.TYPE_WORK = position + 1;

			}

			@Override
			public void onNothingSelected(AdapterView<?> arg0) {
				// TODO Auto-generated method stub

			}

		});

		mButtonSave.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				Reference.saveData(getApplicationContext());
				Toast.makeText(getApplicationContext(),
						" Đã lưu cài đặt ",
						Toast.LENGTH_SHORT).show();				
			}
		});

		// spinnerType.setOnItemSelectedListener(this);

		// Look up the AdView as a resource and load a request.
		AdView adView = (AdView) this.findViewById(R.id.adView2);
		AdRequest adRequest = new AdRequest.Builder()
				.addTestDevice(AdRequest.DEVICE_ID_EMULATOR) // Emulator
				 .addTestDevice("D2CFFD5B967879F")
				.addTestDevice("2EFFE071A2F36DEF").build();
		adView.loadAd(adRequest);
	}

}
